package com.ticket.sass.admin.business.impl;

import cn.hutool.core.util.StrUtil;
import com.ticket.sass.admin.business.AreaBusiness;
import com.ticket.sass.admin.dto.output.area.AreaListOutput;
import com.ticket.sass.admin.model.PageModel;
import com.ticket.sass.admin.service.impl.AreaServiceImpl;
import com.ticket.sass.admin.util.ModelUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.TypeToken;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ywb
 * @date 2022-09-27 16:34
 */

@Slf4j
@Service
@AllArgsConstructor
public class AreaBusinessImpl implements AreaBusiness {
    
    final ModelUtil modelUtil;
    final AreaServiceImpl areaService;

    @Override
    public PageModel<AreaListOutput> list(String parentCode) {
        if (StrUtil.isEmpty(parentCode)) {
            parentCode = "100000000000";
        }
        List<AreaListOutput> areas = modelUtil.listToList(
            areaService.listBy(parentCode),
            new TypeToken<List<AreaListOutput>>() {}.getType());
        
        return new PageModel<>((long)areas.size(), areas);
    }
}
